package game.view;

import game.model.DummyRaumschiff;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class View extends javax.swing.JFrame {

	{
		// Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager
					.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// ship shape: triangle
	// |\
	// |/
	final int triangle_width = 30;
	final int triangle_height = 20;
	final int[] xCornerPoints = new int[] { -triangle_width / 2,
			-triangle_width / 2, triangle_width / 2 };
	final int[] yCornerPoints = new int[] { -triangle_height / 2,
			triangle_height / 2, 0 };

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				View inst = new View();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public View() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			pack();
			this.setSize(800, 600);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
	}

	
	@Override
	public void paint(Graphics g) {
	
		Graphics2D g2d = (Graphics2D) g;

		super.paintComponents(g);

		int shipCenterX, shipCenterY; // ship center position

		double angle = -DummyRaumschiff.getInstance().getAngle();

		shipCenterX = DummyRaumschiff.getInstance().getCenterX();
		shipCenterY = DummyRaumschiff.getInstance().getCenterY();

		// shipCenterX = 0;
		// shipCenterY = 0;

		int[] xPoints = new int[3];
		int[] yPoints = new int[3];

		for (int i = 0; i < 3; i++) {
			xPoints[i] = (int) (xCornerPoints[i] * Math.cos(angle) - yCornerPoints[i]
					* Math.sin(angle))
					+ shipCenterX;
			yPoints[i] = (int) (xCornerPoints[i] * Math.sin(angle) + yCornerPoints[i]
					* Math.cos(angle))
					+ shipCenterY;
		}

		Polygon ship = new Polygon(xPoints, yPoints, 3);

		g2d.fillPolygon(ship);

		g2d.setPaint(Color.RED);
		g2d.drawOval(shipCenterX - 2, shipCenterY - 2, 4, 4);


	}
}
